package com.linzm.utils;

import java.text.MessageFormat;

/**
 * HttpProtocolUtil
 *
 * @Date: 2023/11/6 21:40
 * @User linziming
 */
public class HttpProtocolUtil {
    /**
     * 为响应码200提供请求头信息
     */
    public static String getHttpHeader200(long contentLength) {
        return MessageFormat.format("HTTP/1.1 200 OK \nContent-Type: text/html \nContent-Length: {0}\n\r\n", contentLength);
    }

    /**
     * 为响应码404提供请求头信息(也包含了数据内容)
     */
    public static String getHttpHeader404() {
        String str404 = "<h1>404 not found</h1>";
        return MessageFormat.format("HTTP/1.1 404 NOT Found \nContent-Type: text/html \nContent-Length: {0}\n\r\n{1}", str404.getBytes().length, str404);
    }
}
